package com.eulog.client.blackJack;

import java.util.ArrayList;

import com.eulog.client.trump.TrumpCard;
import com.eulog.client.trump.TrumpHuman;

public abstract class BlackJackHuman extends TrumpHuman{
	
	protected static final int maxSplit = 3;
	
	protected ArrayList<BlackJackHandCards> handCardsList;
	protected int splitCount;
	
	public BlackJackHuman(int money) {
		super(money);
		handCardsList = new ArrayList<BlackJackHandCards>();
		
		for(int i=0; i<=maxSplit; i++) {
			handCardsList.add(new BlackJackHandCards());			
		}

		setHandCard(handCardsList.get(0));
		splitCount = 0;
	}
	
	public abstract BlackJackStrategy.SD getNextDecision(BlackJackStrategy blackJackStrategy, TrumpCard dealerOpenCard,int splitNo, BlackJackRules rules);
	
	public void clear() {
		clearCard();
	}
	
	public void clearCard() {
		for (BlackJackHandCards h: handCardsList) {
			h.clear();
		}
		splitCount = 0;
	}
	
	public int getSplitCount() {return splitCount;}
	
	public boolean isBusted(int index) {return handCardsList.get(index).isBusted();}
	
	public int getCardSize(int index) {return handCardsList.get(index).size();}
	
	public int calculateRanks(int index) {return handCardsList.get(index).calculateRanks();}
	
	public boolean isBlackJack(int index) {
		if(splitCount>0) return false;
		return handCardsList.get(index).isBlackJack();
	}
	
	public boolean isSoft(int index) {return handCardsList.get(index).isSoft();}
	
	public void addHandCard(TrumpCard card, int splitNo) {handCardsList.get(splitNo).add(card);}
	
	public String toString() {
		String name = "";
		
		int i=0;
		for (BlackJackHandCards h: handCardsList) {
			if(h.size()>0) {
				if(i>0) name += " | ";
				name += h + "[" + h.calculateRanks() + "]";
				i++;
			}
		}
		return name;
	}
	
	public void addDecision(BlackJackStrategy.SD d, int splitNo) {handCardsList.get(splitNo).addDecision(d);}
	
	
}
